package com.egene.tw.data.utils;

import com.egene.tw.data.entity.FatigueData;

/**
 * Created by wzx on 2018/7/11.
 */

public class CalUtils {

    //公式 距離=(身高*0.45)*步數
    public static double calJuLi(int height, int step) {
        if (height == 0) {
            return 0.33 * step / 1000;
        }
        return height * 0.33 * step / 1000;
    }

    /**
     * 计算疲劳值
     */
    public static float calFatigue(FatigueData fatigueData, float egeneValue) {
        double sleep = fatigueData.getShallowValue() + fatigueData.getDeepValue() / 60.0;
        int oxygen = fatigueData.getOxygen();
        int heart = fatigueData.getHeart();
        int bloodHight = fatigueData.getBloodHigh();
        int bloodLow = fatigueData.getBloodLow();
        int step = fatigueData.getStep();

        float point = 0;
        //睡眠
        if (sleep < 5) {
            point += 1;
        } else {
            point += 0;
        }

        //血氧
        if (oxygen >= 98) {
            point += 0;
        } else if (oxygen == 97) {
            point += 1;
        } else if (oxygen == 96) {
            point += 2;
        } else {
            point += 3;
        }

        //血压
        if (bloodHight <= 90) {
            point += 3;
        } else if (bloodHight <= 130) {
            point += 0;
        } else if (bloodHight <= 149) {
            point += 1;
        } else if (bloodHight <= 159) {
            point += 2;
        } else {
            point += 3;
        }

        //心率
        if (heart <= 104) {
            point += 0;
        } else if (heart <= 109) {
            point += 1;
        } else if (heart <= 119) {
            point += 2;
        } else {
            point += 3;
        }

        //步数
        if (step <= 9000) {
            point += 1;
        } else if (step <= 10000) {
            point += 0;
        } else if (step <= 12000) {
            point += 0;
        } else {
            point += 1;
        }

        return 14 - (point + egeneValue);
    }

    public static String getFatigueDesc(float point) {
        point = 14 - point;
        if (point == 0) {
            return "--";
        }
        String desc = "";
        if (point <= 5) {
            desc = "良好";
        } else if (point <= 9) {
            desc = "普通";
        } else {
            desc = "需注意";
        }
        return desc;
    }
}
